<script setup>
import cartDetails from "./cartDetails.vue";
import Checkout from "../checkout/checkout.vue";
import cartBag from "@/assets/bag.png";
import { useHamburgerStore } from "@/store/hamburger";
import { ref } from "vue";

const hamburgerStore = useHamburgerStore();
const showDetails = ref(false);
const showCheckout = ref(false);
</script>

<template>
  <Checkout @close="showCheckout = false" :is-show="showCheckout"></Checkout>
  <cartDetails :is-show="showDetails" @hide="showDetails = false" />
  <div class="card-bar">
    <div class="cart-bag">
      <img :src="cartBag" alt="" />
      <span v-show="hamburgerStore.totalGoods > 0" class="total-count">{{
        hamburgerStore.totalGoods
      }}</span>
    </div>
    <div class="total-message">
      <p v-show="hamburgerStore.totalGoods <= 0" class="empty">未选购商品</p>
      <p
        @click="showDetails = true"
        v-show="hamburgerStore.totalGoods > 0"
        class="has-goods"
      >
        {{ hamburgerStore.totalPrice }}
      </p>
    </div>
    <template v-if="hamburgerStore.totalGoods > 0">
      <button
        @click="showCheckout = hamburgerStore.totalGoods > 0"
        class="checkout-btn"
      >
        去结算
      </button>
    </template>
    <template v-if="hamburgerStore.totalGoods <= 0">
      <button class="checkout-btn disabled">去结算</button>
    </template>
  </div>
</template>

<style scoped>
.card-bar {
  width: 710rem;
  height: 100rem;
  position: fixed;
  bottom: 40rem;
  /* margin: 0 20rem; */
  margin: 0 auto;
  left: 0;
  right: 0;
  border-radius: 50rem;
  background-color: rgb(58, 58, 58);
  z-index: 999;
}
.cart-bag {
  position: absolute;
  bottom: -10rem;
  left: 0;
  width: 100rem;
}
.total-count {
  position: absolute;
  top: 5rem;
  left: 77rem;
  width: 40rem;
  height: 40rem;
  color: #fff;
  text-align: center;
  line-height: 40rem;
  font-weight: bold;
  background-color: red;
  border-radius: 50%;
}
.total-message {
  margin-left: 140rem;
  line-height: 100rem;
}
.empty,
.has-goods {
  color: rgb(150, 150, 150);
  font-size: 37rem;
  font-weight: bold;
}
.has-goods {
  color: #fff;
}
.has-goods::before {
  content: "￥";
  font-size: 31rem;
}
.checkout-btn {
  position: absolute;
  top: 0;
  right: 0;
  width: 220rem;
  height: 100%;
  border-radius: 50rem;
  font-size: 36rem;
  font-weight: bold;
  border: none;
  background-color: rgb(250, 188, 0);
}
.disabled {
  background-color: #777;
  color: #ccc;
}
</style>
